﻿#region LicenseHeader

// Copyright 2012 The Trustees of Indiana University.  All rights reserved.
// 
// The Indiana University licenses this file to you under the Apache License, 
// Version 2.0 (the "License"); you may not use this file except in compliance 
// with the License.  You may obtain a copy of the License at 
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
// See the License for the specific language governing permissions and 
// limitations under the License.
// 
// @author Thilina Gunarathne (tgunarat@indiana.edu)

#endregion

#region

using System;

#endregion

namespace AzureMRCore.DataTypes
{
    public interface IValue
    {
        string GetTextValue();
        Boolean ParseValue(object value);
        byte[] GetBytes();
        Boolean FromBytes(byte[] value);
        long Size();
    }

    /// <summary>
    ///     To be To be used as a dummy when we need an optional Type argument Eg: Mapper with no broadcast input. ///
    /// </summary>
    public class NullValue : IValue
    {
        #region IValue Members

        public string GetTextValue()
        {
            return null;
        }

        public bool ParseValue(object value)
        {
            return true;
        }

        public byte[] GetBytes()
        {
            return null;
        }

        public bool FromBytes(byte[] value)
        {
            return true;
        }

        public long Size()
        {
            return 0;
        }

        #endregion
    }

    /*  public static class ValueExtentions
    {
        public static object ParseValue(this object thisObject, object value, out bool success)
        {
            success = true;
            return value;
        }

        public static object ParseValue(this string thisObject, object value, out bool success)
        {
            success = true;
            return value.ToString();
        }

        public static double ParseValue(this double thisObject, object value, out bool success)
        {
            if (value is double)
            {
                success = true;
                return (double) value;
            }
            if (value is string)
            {
                double val;
                success = Double.TryParse((string) value, out val);
                if (success)
                {
                    return val;
                }
            }
            success = false;
            return 0;
        }

        public static FileInfo ParseValue(this FileInfo thisObject, object value, out bool success)
        {
            if (value is string)
            {
                success = true;
                return new FileInfo((string) value);
            }
            else if (value is FileInfo)
            {
                success = true;
                return (FileInfo) value;
            }
            else
            {
                success = false;
                return null;
            }
        }
    }*/
}